import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:school_safe_teacher/resourse/app_colors.dart';
import 'package:school_safe_teacher/widget/my_widget.dart';

import 'package:webview_flutter/webview_flutter.dart';

import 'action.dart';
import 'state.dart';

Widget buildView(
    BaseWebState state, Dispatch dispatch, ViewService viewService) {
  return stateBar(
      child: Column(
        children: [
          Container(
            color: AppColors.toolBarColor,
            padding: EdgeInsets.only(
                left: 15,
                right: 15,
                top: MediaQuery.of(viewService.context).padding.top),
            child: noRightIconBar(
                context: viewService.context,
                title: "",),
          ),
          Expanded(
              child: WebView(
                  initialUrl: state.url,
                  javascriptMode: JavascriptMode.unrestricted,
                  onWebViewCreated: (WebViewController webViewController) {
                    state..webViewController = webViewController;
                  }))
        ],
      ),
      context: viewService.context);
}

Future<bool> _goBack(
    BaseWebState state, Dispatch dispatch, ViewService viewService) async {
  if (state.webViewController != null &&
      await state.webViewController.canGoBack()) {
    state.webViewController.goBack();
    return false;
  }
  return true;
}
